package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.google.common.collect.Lists;
import org.example.entity.Test;
import org.example.entity.TestData;
import org.example.mapper.TestDataMapper;
import org.example.service.TestDataService;
import org.example.util.JobUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 *
 * @author yangzhenyu
 * @since 2023-04-26 03:46:56
 */
@Service
public class TestDataServiceImpl extends ServiceImpl<TestDataMapper, TestData> implements TestDataService {
    @Override
    public Boolean addAll(int num) {
        List<TestData> list = Lists.newArrayList();
        for (int index = 0;index <num ; index++){
            TestData test = TestData.builder()
                    .age(JobUtil.nextInt(10,110))
                    .name(JobUtil.simpleUUID())
                    .build();
            list.add(test);

        }
        return this.saveBatch(list);
    }

    /**
     * @description: 整理插入数据
     * @author yangzhenyu
     * @date 2023/4/26 15:52
     * @version 1.0
     */
    @Override
    public List<TestData> setData(List<Test> searchParam) {
        List<TestData> list = Lists.newArrayList();
        for (Test test:searchParam){
            TestData build = TestData.builder()
                    .age(test.getAge())
                    .name(test.getName())
                    .createTime(new Date())
                    .build();
            list.add(build);
        }
        return list;
    }

}
